#include "StdAfx.h"
#include "DownloadJob.h"
#include <fstream>

using namespace std;

CDownloadJob::CDownloadJob(void)
{
	InitializeCriticalSection(&m_csWriteFile);
	m_bStartSniffing = FALSE;
	m_uJobID = 0;
}


CDownloadJob::~CDownloadJob(void)
{
	DeleteCriticalSection(&m_csWriteFile);
}

VOID CDownloadJob::WriteToFile(DWORD nOffset, PUCHAR lpData, DWORD nSize)
{
	if(nSize > 0)
	{
		EnterCriticalSection(&m_csWriteFile);
		fstream fs(m_strFilePath, ios_base::in | ios_base::out | ios_base::binary);
		if(!fs.is_open())
		{
			fs.open(m_strFilePath, ios_base::out | ios_base::binary | ios_base::app);
		}
		fs.seekp(nOffset, ios_base::beg);
		fs.write((PCHAR)lpData, nSize);
		fs.close();
		LeaveCriticalSection(&m_csWriteFile);
	}
}

DWORD CDownloadJob::GetJobID()
{
	return m_uJobID;
}